package artibella.ui.combos
{
	import flash.events.MouseEvent;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	/**
	 * ...
	 * @author pbordachar
	 */
	
	public class Combo extends ACombo
	{
		private var _txt:TextField;
		private var _format:TextFormat;
		
		public function Combo( ) 
		{
			super();
			
			_initFormat();
		}

		protected function _initFormat():void
		{
			_format = new TextFormat();
			_format.font = "Arial";
			_format.color = 0x000000;
			_format.size = 12;
		}
		
		public function setTextFormat( tf:TextFormat ):void
		{
			_format = tf;
			
			if ( _txt != null ) {
				_txt.setTextFormat( _format );
			}
		}
		
		// - - -
		
		override public function setDefaultSelection( i:int, str:String = null ):void
		{
			super.setDefaultSelection( i, str );
			
			if ( _txt != null ) {
				_txt.htmlText = _defaultText;
				_txt.setTextFormat( _format );
			}
		}
		
		override protected function _setHeaderText():void
		{
			_txt = new TextField();
			_txt.defaultTextFormat = _format;
			_txt.embedFonts = true;
			_txt.antiAliasType = AntiAliasType.ADVANCED;
			_txt.autoSize = TextFieldAutoSize.LEFT;
			_txt.multiline = false;
			_txt.wordWrap = false;
			_txt.selectable = false;
			_txt.width = _header_bg.width - _header_btn.width - 10;
			_txt.htmlText = _defaultText;
			_txt.x = 5;
			_txt.y = 2;
			
			_header.addChild( _txt );
		}
		
		override public function selectItem( e:MouseEvent ):void
		{
			super.selectItem( e );
			
			var item:ComboListItem = e.target as ComboListItem;
			_txt.htmlText = item.text;
			
			//trace( _txt.htmlText + " = " + item.text );
			
			dispatchEvent( new ComboEvent( ComboEvent.SELECTED, item.indice, item.text ) );
			
		}
	}
}